package cn.sc.summer.gateway.config;

import cn.sc.summer.gateway.swagger.SwaggerResourceHandler;
import cn.sc.summer.gateway.swagger.SwaggerSecurityHandler;
import cn.sc.summer.gateway.swagger.SwaggerUIHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 类名：路由转发，swagger基础接口路由配置信息
 *
 * @author a-xin
 * @date 2023/8/18 10:47
 */
@Slf4j
@Profile({"dev-8", "dev-17"})
@Configuration
@AllArgsConstructor
public class RouterSwaggerConfig {

    private final SwaggerSecurityHandler swaggerSecurityHandler;

    private final SwaggerUIHandler swaggerUIHandler;

    private final SwaggerResourceHandler swaggerResourceHandler;

    @Bean
    public RouterFunction<ServerResponse> routerFunction() {
        log.info("==> Start Initializing the gateway [swagger] routing config...");
        return RouterFunctions.route(
                        RequestPredicates.GET("/swagger-resources/configuration/security")
                                .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), swaggerSecurityHandler)
                .andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
                        .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), swaggerUIHandler)
                .andRoute(RequestPredicates.GET("/swagger-resources")
                        .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), swaggerResourceHandler)
                ;
    }

}

